package com.heima.freemarker.controller;

import com.heima.freemarker.pojo.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Controller
public class FreemarkerController {

    @GetMapping
    public String test1(Model model){
        model.addAttribute("name","冬哥真帅！！！");
        Student student = new Student();
        student.setName("龙哥真帅！！！");
        student.setAge(11);
        model.addAttribute("stu",student);
        return "01-basic";
    }

    @GetMapping("/list")
    public String test2(Model model){

        Student student1 = new Student();
        student1.setName("张三");
        student1.setAge(18);
        student1.setMoney(888.00);

        Student student2 = new Student();
        student2.setName("张三");
        student2.setAge(12);
        student2.setMoney(82.00);
        List<Student> list = new ArrayList<>();
        list.add(student1);
        list.add(student2);
        model.addAttribute("stuList",list);
        System.out.println(list);

        HashMap<String,Student> map = new HashMap<>();
        map.put("stu1",student1);
        map.put("stu2",student2);
        model.addAttribute("stuMap",map);
        System.out.println(map);


        return "02-basic";
    }

}
